/**
 * 公共static 函数
 * Created by xmh on 2017/11/20.
 */

import {Injectable} from '@angular/core';
import {ParamService} from "./paramService";


@Injectable()
export class UtilService{

  constructor(){

  }
  /**
   * trim
   * @param str
   * @returns {string}
   */
  public static trimStr(str) {
    return str ? str.replace(/(^\s*)|(\s*$)/g, "") : "";
  }


  /**
   * 获得ParamService.appParams里面的数据，
   * DATA_NAME和DATA_ID 可以根据具体的需要进行添加，不过我粗略看了下，这两个够用了，如果有需要可以按需求添加改造，直接再上面修改就可以。
   * 注意结构[{'DATA_NAME':'xxx','DATA_ID':'xx'},{'DATA_NAME':'xxx','DATA_ID':'xx'}]
   * @param {string} strName
   * @returns {any}
   */
  public static getRighArraybyName(strName:string){
    let resArray:any=[];
    for (let prop in ParamService.appParams) {
      if(prop.indexOf(strName)>=0){
        console.log( ParamService.appParams[prop].DATA_NAME);
        console.log( ParamService.appParams[prop].DATA_ID);
        let resTemp={'DATA_NAME':ParamService.appParams[prop].DATA_NAME,'DATA_ID':ParamService.appParams[prop].DATA_ID};
        resArray.push(resTemp);
      }
    }
    return resArray;
  }


  /**
   * 十二个月份
   */
  public static getMonthName(month:string){
    let monthName = month;
    switch (month) {
      case "01"       : monthName = '1月'; break;
      case "02"       : monthName = '2月'; break;
      case "03"       : monthName = '3月'; break;
      case "04"       : monthName = '4月'; break;
      case "05"       : monthName = '5月'; break;
      case "06"       : monthName = '6月'; break;
      case "07"       : monthName = '7月'; break;
      case "08"       : monthName = '8月'; break;
      case "09"       : monthName = '9月'; break;
      case "10"       : monthName = '10月'; break;
      case "11"       : monthName = '11月'; break;
      case "12"       : monthName = '12月'; break;
      case "1月"       : monthName = '01'; break;
      case "2月"       : monthName = '02'; break;
      case "3月"       : monthName = '03'; break;
      case "4月"       : monthName = '04'; break;
      case "5月"       : monthName = '05'; break;
      case "6月"       : monthName = '06'; break;
      case "7月"       : monthName = '07'; break;
      case "8月"       : monthName = '08'; break;
      case "9月"       : monthName = '09'; break;
      case "10月"       : monthName = '10'; break;
      case "11月"       : monthName = '11'; break;
      case "12月"       : monthName = '12'; break;
    }
    return monthName;
  }

  /**
   * 根据model 返回苹果手机类型
   * @param {string} model
   * @returns {string}
   */
  public static getIOSMobileModel(model:string){
    let modelName = model;
    switch (model){
      case "iPhone7,1"       : modelName = 'iPhone 6 Plus'; break;
      case "iPhone7,2"       : modelName = 'iPhone 6'; break;
      case "iPhone8,1"       : modelName = 'iPhone 6s'; break;
      case "iPhone8,2"       : modelName = 'iPhone 6s Plus'; break;
      case "iPhone9,1"       : modelName = 'iPhone 7'; break;
      case "iPhone9,2"       : modelName = 'iPhone 7'; break;
      case "iPhone9,3"       : modelName = 'iPhone 7'; break;
      case "iPhone9,4"       : modelName = 'iPhone 7 Plus'; break;
    }
    return modelName;
  }


  public static getQuikDateType(type:string){
    let typeName = type;
    switch (type) {
      case "0"       : typeName = '今日'; break;
      case "1"       : typeName = '本周'; break;
      case "2"       : typeName = '本月'; break;
      case "3"       : typeName = '上月'; break;
      case "今日"       : typeName = '0'; break;
      case "本周"       : typeName = '1'; break;
      case "本月"       : typeName = '2'; break;
      case "上月"       : typeName = '3'; break;
    }
    return typeName;
  }

  public static getCallType(type:string){
    let typeName = type;
    switch (type) {
      case "0"       : typeName = '未拨打'; break;
      case "1"       : typeName = '已拨打'; break;
      case "未拨打"       : typeName = '0'; break;
      case "已拨打"       : typeName = '1'; break;
    }
    return typeName;
  }

  public static getFollowType(type:string){
    let typeName = type;
    switch (type) {
      case "0"       : typeName = '未标记'; break;
      case "1"       : typeName = '无意向'; break;
      case "2"       : typeName = '待跟进'; break;
      case "3"       : typeName = '已成交'; break;
      case "未标记"       : typeName = '0'; break;
      case "无意向"       : typeName = '1'; break;
      case "待跟进"       : typeName = '2'; break;
      case "已成交"       : typeName = '3'; break;
    }
    return typeName;
  }

  public static getDateSellist(){
    let itemlist: any = [];
    itemlist[0] = {
      type: 'radio',
      label: '今日',
      value: 0
    };
    itemlist[1] = {
      type: 'radio',
      label: '本周',
      value: 1
    };
    itemlist[2] = {
      type: 'radio',
      label: '本月',
      value: 2
    };
    itemlist[3] = {
      type: 'radio',
      label: '上月',
      value:3
    };
    return itemlist;
  }
  public static getfollostate(){
    let itemlist: any = [];
    itemlist[0] = {
      type: 'radio',
      label: '未标记',
      value: 0
    };
    itemlist[1] = {
      type: 'radio',
      label: '无意向',
      value: 1
    };
    itemlist[2] = {
      type: 'radio',
      label: '待跟进',
      value: 2
    };
    itemlist[3] = {
      type: 'radio',
      label: '已成交',
      value:3
    };
    return itemlist;
  }

  public static getCallStateList(){
    let itemlist: any = [{ title: '总数', name: 'count', value: 0 },
      { title: '未打', name: 'callstate0', value: 0 },
      { title: '已打', name: 'callstate1', value: 0 },
      { title: '无意', name: 'followState1', value: 0 },
      { title: '待跟', name: 'followState2', value: 0 },
      { title: '成交', name: 'followState3', value: 0 }];
    return itemlist;
  }

  /**
   * 检测页面是否可需要滑动  true :禁止滑动  false:可以滑动
   */
  public static onTouchMove(inFlag:boolean){
    if (inFlag) {
      document.addEventListener('touchmove', this.onHandler, false);
    } else {
      document.removeEventListener('touchmove', this.onHandler, false);
    }
  }

  private static onHandler(e) {
    e.preventDefault();
  }

}

